//
//  LZAuthorizeManager.m
//  LZBaseDeviceSDK_Example
//
//  Created by panfei mao on 2019/1/7.
//  Copyright © 2019 panfei mao. All rights reserved.
//

#import "LZAuthorizeManager.h"
#import "UIViewController+LZVisible.h"

@implementation LZAuthorizeManager

//  地理位置打开授权
+ (void)authorizeGeographicLocation{
    NSDictionary *infoDict = [NSBundle mainBundle].localizedInfoDictionary;
    if (!infoDict) {
        infoDict = [NSBundle mainBundle].infoDictionary;
    }
    NSString *appName            = [infoDict objectForKey:@"CFBundleDisplayName"];
    if (appName == nil) {
        appName = @"";
    }
    NSString *alertMessage       = [NSString stringWithFormat:@"请允许%@访问地理位置", appName];
    NSString *title              = [NSString stringWithFormat:@"温馨提示"];
    
    [self authorizeAlertWithTitle:title message:alertMessage];
}

//  权限打开弹窗
+ (void)authorizeAlertWithTitle:(NSString *)title message:(NSString *)message{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction  = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *setupAction   = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:setupAction];
    
    UIViewController *currentVC = [UIViewController currentViewController];
    [currentVC presentViewController:alertController animated:YES completion:nil];
}

@end
